<?php
declare (strict_types = 1);

namespace app\api\controller;

use think\Request;
use think\facade\Db;

class Commission extends Base
{
    /**
     * 拥挤手续费
     * @return false|string
     */
    public function statistics()
    {
        $date = strtotime(date("Y-m-d"),time());

        $starttimes = $date-60*60*24;

        $endtime = date('Y-m-d H:i:s',$date);

        $starttime = date('Y-m-d H:i:s',$starttimes);

        $sum = Db::table('ea_com_amounts')
            ->whereBetweenTime('created_at',$starttime,$endtime)
            ->count();

        //佣金总额
        $commissionsum = Db::table('ea_com_amounts')
            ->whereBetweenTime('created_at',$starttime,$endtime)
            ->sum('commission');

        $data = Db::table('ea_com_statistics')->insert([
            'count'=>$sum,
            'commissionsum'=>$commissionsum,
            'starttime'=>date('Y-m-d',$starttimes),
            'endtime'=>date('Y-m-d',$date),
        ]);

        return $this->sendJson($data);
    }


    public function com(){

        $endtime = date("Y-m-d",time());

        $data = Db::table('com_statistics')->where('endtime',$endtime)->find();

        return $this->sendJson($data);
    }
}
